package com.example.data_receiver.config;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

// 自定义过滤器类，用于拦截请求并包装请求对象
public class IllegalCharacterFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        if (request instanceof HttpServletRequest) {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            // 包装请求对象，过滤请求体中的非法字符
            IllegalCharacterRequestWrapper requestWrapper = new IllegalCharacterRequestWrapper(httpRequest);
            chain.doFilter(requestWrapper, response);
        } else {
            chain.doFilter(request, response);
        }
    }
}    